Conversation
Agent-Logs-Url: https://github.com/dadhi/FastExpressionCompiler/sessions/12b84d82-7d59-4139-8f30-ddc49bf21766 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dadhi/FastExpressionCompiler/sessions/12b84d82-7d59-4139-8f30-ddc49bf21766 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dadhi/FastExpressionCompiler/sessions/12b84d82-7d59-4139-8f30-ddc49bf21766 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
| public static bool DisableDemit; | ||
|
|
||
| // Tracks the IL offset of each marked label per ILGenerator, used by smart branch emitters to select short form when possible | ||
| internal static readonly ConditionalWeakTable<ILGenerator, Dictionary<Label, int>> _ilLabelPositions = |
There was a problem hiding this comment.
Baa idea unless we limit it being fully on stack and inlined etc. Eg. if you use Stack8 or 16 and overwrite the older indexes in LRU fasion. You don't need weak table is everything is on stack.
If this kind of sinplification is impossible then drop this generalized optimization. We will keep only adhoc places where we know the distances and can apply smsll branches on the spot.
There was a problem hiding this comment.
Dropped the ConditionalWeakTable-based general optimizer entirely (commit f4fc8ab). The PR now only contains the ad-hoc forward-branch short-form replacements for the four known-small patterns where the distance to the target is provably tiny (≤6 bytes): IsFalse, coalesce-with-cast, isLiftedToNull, and logical-operator labelDone.
…y ad-hoc short-form branches Agent-Logs-Url: https://github.com/dadhi/FastExpressionCompiler/sessions/20368e58-840b-428b-b785-c852cbfd5438 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Branch instructions like
Br,Brtrue,Brfalseencode a 4-byte offset by default, but have short-form variants (Br_S,Brtrue_S,Brfalse_S) using a 1-byte signed offset when the target is within ±127 bytes. Previously, a blanket replacement broke large switch statements. This PR applies short-form branches only at specific ad-hoc sites where the distance to the target is provably tiny.Changes
Specific forward-branch optimizations (always safe, hardcoded)
Patterns where the skipped IL is provably small enough to always use the short form:
IsFalseunaryBrfalse→Brfalse_S,Br→Br_SBr→Br_SCastclass)isLiftedToNullcomparisonBrfalse→Brfalse_S,Brtrue→Brtrue_SlabelDoneBr→Br_SLdc_I4_0/1)Tests updated
One existing opcode-assertion test updated to expect the new short-form opcode where the optimization applies (
Issue159).